﻿namespace keyboardproject
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello, World!");
            Random rand = new Random();
            Console.WriteLine("请输入进行次数");
            int times = int.Parse(Console.ReadLine());
            //起始时间
            int setupsecond = DateTime.Now.Second;
            int setupminite = DateTime.Now.Minute;
            //错误次数
            int wrongtime = 0;
            for(int time = 0; time < times; time++)
            {

                char key='0';
                while (true)
                {
                    System.Threading.Thread.Sleep(200);
                    Console.Clear();
                    int rnd = (rand.Next(1, 5));
                    if (rnd== 1)
                    {
                        key = 'w';
                        Console.WriteLine(key);
                    }
                    else if(rnd== 2)
                    {
                        key = 'a';
                        Console.WriteLine(key);
                    }
                    else if (rnd == 3)
                    {
                        key = 's';
                        Console.WriteLine(key);
                    }
                    else if (rnd == 4)
                    {
                        key = 'd';
                        Console.WriteLine(key);
                    }
                    char inputkey =Console.ReadKey(true).KeyChar;
                    if(inputkey == key)
                    {
                        Console.WriteLine("还行 算你对");

                        break;
                    }
                    else
                    {
                        Console.WriteLine("输错了 服了");
                        char right = '0';
                        wrongtime++;
                        //直到符合条件 跳出循环
                        while (key != right)
                        {
                            Console.WriteLine(key);
                            right = Console.ReadKey(true).KeyChar;
                            if (right == key)
                                break;
                            else
                                wrongtime++;
                        }
                        Console.WriteLine("终于对了");                     
                    }
                }
            }
            //结束时间
            int endupsecond = DateTime.Now.Second;
            int endupminute = DateTime.Now.Minute;
            //统计时间
            int spendtime = (endupminute - setupminite) * 60 + (endupsecond - setupsecond);
            Console.WriteLine("你一共用时" + spendtime + "秒");
            Console.WriteLine("错误了" + wrongtime + "次");
        }
    }
}
